#include "lcd_task.h"
#include <stdio.h>
#include "main.h"
#include "lcd.h"
#include "adc.h"
#include "tim.h"


// R39、R40CCR寄存器值
static uint32_t R39_CCR = 0;
static uint32_t R40_CCR = 0;


void LCD_Task(void)
{
  char str[24] = {0};
  
  HAL_ADC_Start(&hadc1);
  sprintf(str, "R37:%f            ", HAL_ADC_GetValue(&hadc2)/4095.0f * 3.3f);
  LCD_DisplayStringLine(Line0, (u8 *)str);
  HAL_ADC_Start(&hadc2);
  sprintf(str, "R38:%f            ", HAL_ADC_GetValue(&hadc1)/4095.0f * 3.3f);
  LCD_DisplayStringLine(Line1, (u8 *)str);
  
  sprintf(str, "R39:%f            ", 1000000.0f / (R39_CCR+1));
  LCD_DisplayStringLine(Line3, (u8 *)str);
  HAL_ADC_Start(&hadc2);
  sprintf(str, "R40:%f            ", 1000000.0f / (R40_CCR+1));
  LCD_DisplayStringLine(Line4, (u8 *)str);
}

/**
 * @brief 重写输入捕获中断回调
 */
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
  if(htim == &htim2)
  {
    R40_CCR = htim->Instance->CCR1;
  }
  if(htim == &htim3)
  {
     R39_CCR = htim->Instance->CCR1;
  }
}
